package com.freedom.sql.jdbc.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class FileUtils {
	private static final Logger logger = LogManager.getLogger(FileUtils.class);

	public static String readFile(String fileName) throws Exception {
		StringBuilder content = new StringBuilder();
		BufferedReader reader = null;
		try {
			// 一次读入一行，直到读入null为文件结束
			reader = new BufferedReader(new FileReader(new File(fileName)));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				content.append(tempString);
			}
		} catch (Exception e) {
			LoggerUtils.error(logger, e.toString());
			throw new Exception(e);
		} finally {
			if (null != reader) {
				try {
					reader.close();
				} catch (Exception e1) {
				}
			}
		}
		return content.toString();
	}
}
